package com.tojabo.swing.seventeen_thead;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class InvokeLaterDemo1 {
	static process p;

	public static void main(String[] args) {
		try {
			SwingUtilities.invokeLater(new Runnable() {
				public void run() {
					p = new process();
					try {
						p.sleep(30000);
					} catch (Exception e) {
					}
				}
			});
		} catch (Exception e) {
		}
		JFrame frame = new JFrame("Swing多线程测试程序");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JPanel panel = new JPanel();
		frame.setContentPane(panel);
		JButton button1 = new JButton("按钮一");
		JButton button2 = new JButton("按钮二");
		JButton button3 = new JButton("按钮三");
		JButton button4 = new JButton("按钮四");
		panel.setLayout(new GridLayout(2, 2));
		panel.add(button1);
		panel.add(button2);
		panel.add(button3);
		panel.add(button4);
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int width = screenSize.width;
		int height = screenSize.height;
		int x = (width - process.WIDTH) / 2;
		int y = (height - process.HEIGHT) / 2;
		frame.setLocation(x, y);
		frame.setVisible(true);
		//frame.setResizable(false);
	}
}

class process extends Thread {
	static final int WIDTH = 700;
	static final int HEIGHT = 400;

	public process() {
		JFrame frame = new JFrame("Swing多线程测试程序");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		JPanel panel = new JPanel();
		frame.setContentPane(panel);
		JButton button1 = new JButton("按钮一");
		JButton button2 = new JButton("按钮二");
		JButton button3 = new JButton("按钮三");
		JButton button4 = new JButton("按钮四");
		panel.setLayout(new GridLayout(2, 2));
		panel.add(button1);
		panel.add(button2);
		panel.add(button3);
		panel.add(button4);
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int width = screenSize.width;
		int height = screenSize.height;
		int x = (width - WIDTH) / 2;
		int y = (height - HEIGHT) / 2;
		frame.setLocation(x, y);
		frame.setVisible(true);
		//frame.setResizable(false);
	}
}